using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.Networking;

public class AboutAssetBundle
{
    [MenuItem("Asset Bundle/build assetbundle")]
    static void BuildAssetBundle()
    {
        string path = Application.streamingAssetsPath;

        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }

        AssetBundleBuild[] builds = new[]
        {
            new AssetBundleBuild()
            {
                assetBundleName = "go",
                assetBundleVariant = "unity3d",
                assetNames = new[] {"Assets/Prefabs/Cube.prefab"}
            }
        };

        BuildPipeline.BuildAssetBundles(path, builds, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneWindows);
    }

    [MenuItem("Asset Bundle/Load")]
    static void Load()
    {
        // AssetBundle.LoadFromFile()
        // UnityWebRequest.Get()

        var asset = AssetBundle.LoadFromFile($"{Application.streamingAssetsPath}/go.unity3d");
        if (asset == null)
            return;
        var cube = asset.LoadAsset<GameObject>("Cube");
        GameObject.Instantiate(cube, Vector3.zero, Quaternion.identity);
    }
}